﻿using System;
using System.Web.UI;

namespace SlidingButtons.Attributes
{
  [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
  internal sealed class CssResourceAttribute : Attribute
  {
    /// <summary>
    /// Creates a css resource based on the full resource name
    /// </summary>
    /// <param name="fullResourceName">The fully-qualified name of the resource</param>
    public CssResourceAttribute(String fullResourceName)
    {
      if (fullResourceName == null) throw new ArgumentNullException("fullResourceName");
      m_ResourcePath = fullResourceName;
    }

    /// <summary>
    /// Creates a css resource based on the css existing in the same namespace as the 
    /// base type it affects
    /// </summary>
    /// <param name="baseType">The type of object this css affects</param>
    /// <param name="resourceName">The name of the css resource</param>
    public CssResourceAttribute(Type baseType, String resourceName)
    {
      if (baseType == null) throw new ArgumentNullException("baseType");
      if (resourceName == null) throw new ArgumentNullException("resourceName");

      String typeName = baseType.FullName;
      int lastDot = typeName.LastIndexOf('.');

      if (lastDot != -1)
      {
        typeName = typeName.Substring(0, lastDot);
      }

      m_ResourcePath = typeName + '.' + resourceName;
    }

    #region ResourcePath

    private String m_ResourcePath = String.Empty;

    /// <summary>
    /// The actual path to the css resource that this attribute represens
    /// </summary>
    public String ResourcePath
    {
      get { return m_ResourcePath; }
    }

    #endregion
  }
}
